package tests;

import common.AutoTestUtil;
import org.openqa.selenium.By;

import java.io.IOException;

public class PageLogin extends AutoTestUtil {
    /**
     * 成功登录操作
     * @throws IOException
     * @throws NoSuchMethodException
     */
    public void successLogin() throws IOException, NoSuchMethodException {
        driver.get("http://47.97.70.52:8081/sign-in.html");
        //在进行操作之前，清空填写栏
        driver.findElement(By.cssSelector("#username")).clear();
        driver.findElement(By.cssSelector("#password")).clear();

        //输入正确的用户名与密码
        driver.findElement(By.cssSelector("#username")).sendKeys("朱海洋");
        driver.findElement(By.cssSelector("#password")).sendKeys("zhy19150690517");
        //进行点击操作
        driver.findElement(By.cssSelector("#submit")).click();
        String src = this.getClass().getMethod("successLogin").getName();
        getScreen(src);

        //判断是否登录成功
        try {
            //首页标志
            driver.findElement(By.cssSelector("#article_list_board_title"));
            //导航栏
            driver.findElement(By.cssSelector("#topBoardList > li:nth-child(2) > a > span.nav-link-title"));
        }catch (Exception e){
            System.out.println("successLogin方法出现异常：" + e);
        }
        getScreen(src);
    }
}
